package com.tsingteng.cosfun.ui.message.officalnotification;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.bean.NotificationBean;
import com.tsingteng.cosfun.utils.AppUtils;
import com.tsingteng.cosfun.utils.ImageUtils;
import com.tsingteng.cosfun.utils.TimeUtils;

import java.util.Date;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
/**
 * 官方助手列表适配器
 * 常胜
 * 2018.8.15
 * */
public class OfficalRecyAdapter extends BaseQuickAdapter<NotificationBean.ListBean,BaseViewHolder> {
    public OfficalRecyAdapter() {
        super(R.layout.item_official);
    }

    @Override
    protected void convert(BaseViewHolder helper, NotificationBean.ListBean item) {
        NotificationBean.ListBean.SourceBean source = item.getSource();
        if(source!= null){
            helper.setText(R.id.tv_offical_title,item.getSource().getNickName()+"");
            CircleImageView view = helper.getView(R.id.iv_offical_icon);
            ImageUtils.LoadImage(mContext,item.getSource().getImage(),view);
        }else{
            helper.setText(R.id.tv_offical_title,"官方助手");
        }
        helper.setText(R.id.tv_official_content,item.getContent());
        long createTime = item.getCreateTime();
        //将最新官方通知的时间存放好
        if (helper.getAdapterPosition()==0) {
            AppUtils.setOfficialTime(createTime);
        }
        if(createTime < (60 * 1000 * 5)){
            helper.getView(R.id.tv_offical_time).setVisibility(View.GONE);
        }else{
            helper.setText(R.id.tv_offical_time, TimeUtils.formatChatTime(new Date(createTime)));
        }
    }
}
